<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<div class="Wrapper" id="allBankActDiv" style="display: none;">
    <div id="pageInTab" class="pageInTab">

        <div class="fieldset1 tabel_col clearFix" style="overflow: hidden">
            <div class="fieldBox col_100" id="cstAddDiv" style="display: none;">
                <div class="sqPanel">
                    <div class="sqPanel_head inL">
                        <div class="btnsBox inLC">
                            <span id="cstAddBtn" class="sq-button sq-button-round" style="display: none;" onclick="cstAddBtnEvent('')">添加</span>
                        </div>
                        <span>客户付款账户</span>
                    </div>
                    <div class="sqPanel_body">
                        <div id="ligergrid_cstBank" class="sq-grid"></div>
                    </div>
                </div>
            </div>
            <div class="fieldBox col_100" id="ourComAddDiv" style="display: none;">
                <div class="sqPanel">
                    <div class="sqPanel_head inL">
                        <div class="btnsBox inLC">
                            <span id="ourComAddBtn" class="sq-button sq-button-round" style="display: none;" onclick="ourComAddBtnEvent('')">添加</span>
                        </div>
                        <span>我司收款账户</span>
                    </div>
                    <div class="sqPanel_body">
                        <div id="ligergrid_ourComBank" class="sq-grid"></div>
                    </div>
                </div>
            </div>
        </div>

        <div class="fieldset1 tabel_col clearFix">
            <div class="fieldBox col_100" id="cstAddDiv_1" style="display: none;">
                <div class="sqPanel">
                    <div style="text-align: center;">
                        <font color="#FF0000"><h3>建议使用工商银行、农业银行、中国银行、建设银行、交通银行账户收款。城市商业银行和农村信用合作社，受地域限制易造成银行付款失败。</h3></font>
                    </div>
                    <div class="sqPanel_head inL">
                        <div class="btnsBox inLC">
                            <span id="cstAddBtn_1" class="sq-button sq-button-round" style="display: none;" onclick="cstAddInBtnEvent('')">添加</span>
                            <span id="chooseCstBankInfo" class="sq-button sq-button-round" style="display: none;" onclick="chooseCstBankInfo()">选择账户</span>
                        </div>
                        <span>客户收款账户</span>
                    </div>
                    <div class="sqPanel_body">
                        <div id="ligergrid_cstBank_1" class="sq-grid"></div>
                    </div>
                </div>
            </div>
            <div class="fieldBox col_100" id="ourComAddDiv_1" style="display: none;">
                <div class="sqPanel">
                    <div class="sqPanel_head inL">
                        <div class="btnsBox inLC">
                            <span id="ourComAddBtn_1" class="sq-button sq-button-round" style="display: none;" onclick="ourComOutAddBtnEvent('')">添加</span>
                            <span id="ourComConfirmBtn" class="sq-button sq-button-round" style="display: none;" onclick="confirmStlBankInfo()">确认无误</span>
                        </div>
                        <span>我司付款账户</span>
                    </div>
                    <div class="sqPanel_body">
                        <div id="ligergrid_ourComBank_1" class="sq-grid"></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    var _paySchId = '<%=request.getParameter("paySchId")%>';
    var bankAct = '<%=request.getParameter("bankAct")%>';
    var currentNodeId = '<%=request.getParameter("taskDefKey")%>';
    var insCode = '<%=request.getParameter("bizFlag")%>';
    var cstId = '<%=request.getParameter("cstId")%>';
    var _confirm = '${confirm}';

    var cstBankGrid;//客户付款账号
    var ourComBankGrid;//我司收款账号
    var cstBankGrid_1;//客户收款账号
    var ourComBankGrid_1;//我司付款账号
    var l_hidden_1 = "l-hidden";
    var l_hidden_2 = "l-hidden";
    var l_hidden_3 = "l-hidden";
    var l_hidden_4 = "l-hidden";

    $(function () {
        // 默认全部隐藏
        if (bankAct != '' && bankAct != undefined && bankAct != '0-0-0-0') {
            var arr = bankAct.split('-');
            $("#allBankActDiv").show();
            controlCstAdd(arr[0]);
            controlCstAdd_1(arr[1]);
            controlOurCom_1(arr[2]);
            controlOurCom(arr[3]);
        }
        if (_confirm == '1') {
            $("#ourComConfirmBtn").show();
        }
    });
    // 控制客户付款账号
    function controlCstAdd(flag) {
        // 0~隐藏；1~只读；2~可编辑
        if (flag == '1' || flag == '2') {
            $("#cstAddDiv").show();
            initCstBankGrid();
            if (flag == '2') {
                $("#cstAddBtn").show();
                l_hidden_1 = "";
            }
        }
    }
    // 控制客户收款账号
    function controlCstAdd_1(flag) {
        // 0~隐藏；1~只读；2~可编辑
        if (flag == '1' || flag == '2') {
            $("#cstAddDiv_1").show();
            initCstBankGrid_1();
            if (flag == '2') {
                $("#cstAddBtn_1").show();
                $("#chooseCstBankInfo").show();
                l_hidden_2 = "";
            }
        }
    }
    // 控制我司付款账号
    function controlOurCom_1(flag) {
        // 0~隐藏；1~只读；2~可编辑
        if (flag == '1' || flag == '2') {
            $("#ourComAddDiv_1").show();
            initOurComBankGrid_1();
            if (flag == '2') {
                $("#ourComAddBtn_1").show();
                l_hidden_3 = "";
            }
        }
    }
    // 控制我司收款账号
    function controlOurCom(flag) {
        // 0~隐藏；1~只读；2~可编辑
        if (flag == '1' || flag == '2') {
            $("#ourComAddDiv").show();
            initOurComBankGrid();
            if (flag == '2') {
                $("#ourComAddBtn").show();
                l_hidden_4 = "";
            }
        }
    }
    
    // 1-客户付款账户  2-客户收款账户  3-我司付款账户  4-我司收款账户
    function cstAddBtnEvent(id) {
        $.ligerDialog.open({
            width: 800,
            height: 400,
            title: '编辑客户付款账户',
            url: basePath + '/project/prjPrdPaySchBank/toAddDialogPage.do?bindType=1&paySchId=' + _paySchId + "&id=" + id
        });
    }
    
    function ourComAddBtnEvent(id) {
        $.ligerDialog.open({
            width: 800,
            height: 400,
            title: '编辑我司收款账户',
            url: basePath + '/project/prjPrdPaySchBank/toAddDialogPage.do?bindType=4&paySchId=' + _paySchId + "&id=" + id
        });
    }

    function cstAddInBtnEvent(id) {
        $.ligerDialog.open({
            width: 800,
            height: 400,
            title: '编辑客户收款账户',
            url: basePath + '/project/prjPrdPaySchBank/toAddDialogPage.do?bindType=2&paySchId=' + _paySchId + "&id=" + id
        });
    }

    // 选择客户退款账户
    function chooseCstBankInfo() {
        $.ligerDialog.SQopen({
            width: 950,
            height: 400,
            title: '选择客户收款账户',
            url: basePath + '/settle/bank/toChooseBank.do?cstId=' + cstId + '&paySchId=' + _paySchId,
            fixButtons: true
        });
    }

    function ourComOutAddBtnEvent(id) {
        var url = basePath + '/project/prjPrdPaySchBank/toAddDialogPage.do?bindType=3&paySchId=' + _paySchId + "&id=" + id;
        if (currentNodeId == 'FLOW_0000_065_001_022' || currentNodeId == 'FLOW_0000_065_001_029') {
            // 如果是资金部确认节点 or 三方结清失败异常节点，添加的是资方划扣我司账户数据
            url += "&insCode=" + insCode;
        }
        $.ligerDialog.open({
            width: 800,
            height: 400,
            title: '编辑我司付款账户',
            url: url
        });
    }

    function deleteBankInfoDB(_id, _gridNm) {
        //删除数据库
        var _ids = [];
        _ids.push(_id);
        $.ligerDialog.confirm(LogUtils.LOG_CMM_DELETE_CONFIRM, function (flag) {
            if (flag == false) return;
            var wait_dialog;
            $.ajax({
                type: 'post',
                dataType: 'json',
                data: {ids: JSON.stringify(_ids)},
                url: basePath + '/project/prjPrdPaySchBank/removeByIds.do',
                beforeSend: function () {
                    wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
                },
                success: function (msg) {
                    wait_dialog.close();
                    if (msg.success == 1) {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                        if (_gridNm == 1) {
                            cstBankGrid.reload();
                        } else if (_gridNm == 4) {
                            ourComBankGrid.reload();
                        } else if (_gridNm == 2) {
                            cstBankGrid_1.reload();
                        } else if (_gridNm == 3) {
                            ourComBankGrid_1.reload();
                        }
                    } else {
                        $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                    }
                }
            });
        });
    }

    //初始化客户付款账号信息
    function initCstBankGrid() {
        cstBankGrid = $("#ligergrid_cstBank").ligerGrid({
            url: basePath + '/project/prjPrdPaySchBank/initList.do',
            method: 'get',
            parms: {
                paySchId: _paySchId,
                fundFlowCd: ProjectConstant.CODE_PAY_SCH_FUND_FLOW_CD_INTO,
                fundTypCd: ProjectConstant.CODE_PAY_SCH_FUND_TYP_CD_OUT,
            },
            columns: [
                {display: '付款银行', name: 'bankNm', width: 180},
                {display: '付款账户', name: 'accNm', width: 180},
                {display: '付款账号', name: 'accNo', width: 180},
                {display: '付款金额', name: 'payAmtDouble', width: 100, type: 'text', align: 'right',
                    render: function(rowdata, index, value){
                        return FormatMoney(value, 2);
                    }
                },
                {
                    display: '付款时间', name: 'payTm', width: 100,
                    render: function (rowdata, index, value) {
                        var result = '';
                        if (StringUtils.isEmpty(value)) return result;
                        var date = new Date(value);
                        result = date.Format('yyyy-MM-dd');
                        return result;
                    }
                },
                {display: '备注', name: 'bankRem', minWidth: 150},
                {
                    display: '操作', width: 120, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var d = "";
                        d += '<a class="sq-button-hasicon '+l_hidden_1+'" href="javascript:cstAddBtnEvent(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>编辑</a>';
                        d += '<a class="sq-button-hasicon '+l_hidden_1+'" href="javascript:deleteBankInfoDB(' + rowdata.id + ',' + 1 + ')"><i class="sqBtnIco_7"></i>删除</a>';
                        return d;
                    }
                }
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 200,
            heightDiff: -2,
            enabledEdit: false,
            isScroll: true,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            enabledSort: false
        });
    }

    //初始化我司收款账号信息
    function initOurComBankGrid() {
        ourComBankGrid = $("#ligergrid_ourComBank").ligerGrid({
            url: basePath + '/project/prjPrdPaySchBank/initList.do',
            method: 'get',
            parms: {
                paySchId: _paySchId,
                fundFlowCd: ProjectConstant.CODE_PAY_SCH_FUND_FLOW_CD_INTO,
                fundTypCd: ProjectConstant.CODE_PAY_SCH_FUND_TYP_CD_INTO,
            },
            columns: [
                {display: '收款银行', name: 'bankNm', width: 180},
                {display: '收款账户', name: 'accNm', width: 100},
                {display: '收款账号', name: 'accNo', width: 150},
                {display: '备注', name: 'bankRem', minWidth: 100},
                {
                    display: '操作', width: 120, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var d = "";
                        d += '<a class="sq-button-hasicon '+l_hidden_4+'" href="javascript:ourComAddBtnEvent(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>编辑</a>';
                        d += '<a class="sq-button-hasicon '+l_hidden_4+'" href="javascript:deleteBankInfoDB(' + rowdata.id + ',' + 4 + ')"><i class="sqBtnIco_7"></i>删除</a>';
                        return d;
                    }
                }
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 200,
            heightDiff: -2,
            enabledEdit: false,
            isScroll: true,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            enabledSort: false
        });
    }

    //初始化客户收款账号信息
    function initCstBankGrid_1() {
        cstBankGrid_1 = $("#ligergrid_cstBank_1").ligerGrid({
            url: basePath + '/project/prjPrdPaySchBank/initList.do',
            method: 'get',
            parms: {
                paySchId: _paySchId,
                fundFlowCd: ProjectConstant.CODE_PAY_SCH_FUND_FLOW_CD_OUT,
                fundTypCd: ProjectConstant.CODE_PAY_SCH_FUND_TYP_CD_INTO,
            },
            columns: [
                {display: '收款银行', name: 'bankNm', width: 120},
                {display: '收款账户', name: 'accNm', width: 120},
                {display: '收款账号', name: 'accNo', width: 180},
                {display: '开户行行号', name: 'bankNo', width: 120},
                {display: '开户行支行', name: 'branchBank', width: 180},
                {display: '预留手机号', name: 'actTel', width: 100},
                {display: '证件号码', name: 'identityNo', width: 140},
                {display: '备注', name: 'bankRem', minWidth: 150, editor: {type: 'text'}},
                {
                    display: '操作', width: 120, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var d = "";
                        if (rowdata.cstBankId == null || rowdata.cstBankId == undefined) {
                            d += '<a class="sq-button-hasicon ' + l_hidden_2 + '" href="javascript:cstAddInBtnEvent(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>编辑</a>';
                        }
                        d += '<a class="sq-button-hasicon '+l_hidden_2+'" href="javascript:deleteBankInfoDB(' + rowdata.id + ',' + 2 + ')"><i class="sqBtnIco_7"></i>删除</a>';
                        return d;
                    }
                }
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 200,
            heightDiff: -2,
            enabledEdit: false,
            isScroll: true,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            enabledSort: false
        });
    }
    //初始化我司付款账号信息
    function initOurComBankGrid_1(){
        ourComBankGrid_1 = $("#ligergrid_ourComBank_1").ligerGrid({
            url: basePath + '/project/prjPrdPaySchBank/initList.do',
            method: 'get',
            parms:{
                paySchId:_paySchId,
                fundFlowCd:ProjectConstant.CODE_PAY_SCH_FUND_FLOW_CD_OUT,
                fundTypCd:ProjectConstant.CODE_PAY_SCH_FUND_TYP_CD_OUT,
            },
            columns: [
                {display: '付款银行', name: 'bankNm', width: 220, editor: {type: 'text'}},
                {display: '付款账号', name: 'accNo', width: 180, editor: {type: 'text'}},
                {display: '付款金额', name: 'payAmtDouble', width: 100, type: 'text',align: 'right',
                    render: function (rowdata, index, value) {
                        return StringUtils.isEmpty(value) ? '' : FormatMoney(value, 2);
                    }
                },
                {
                    display: '付款时间', name: 'payTm', width: 150,
                    render: function (rowdata, index, value) {
                        var result = '';
                        if (StringUtils.isEmpty(value)) return result;
                        var date = new Date(value);
                        result = date.Format('yyyy-MM-dd');
                        return result;
                    }
                },
                {display: '备注', name: 'bankRem', minWidth: 140, editor: {type: 'text'}},
                {
                    display: '操作', width: 120, align: 'left',
                    render: function (rowdata, rowindex, value) {
                        var d = "";
                        if (StringUtils.isNotEmpty(rowdata.insCode)) {
                            if (currentNodeId == 'FLOW_0000_065_001_022' || currentNodeId == 'FLOW_0000_065_001_029') {
                                // 资金部确认节点 && insCode不等于空，保证资金部的人才能修改
                                d += '<a class="sq-button-hasicon ' + l_hidden_3 + '" href="javascript:ourComOutAddBtnEvent(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>编辑</a>';
                                d += '<a class="sq-button-hasicon ' + l_hidden_3 + '" href="javascript:deleteBankInfoDB(' + rowdata.id + ',' + 3 + ')"><i class="sqBtnIco_7"></i>删除</a>';
                            }
                        } else {
                            // 财务付款节点 && insCode 等于空
                            d += '<a class="sq-button-hasicon ' + l_hidden_3 + '" href="javascript:ourComOutAddBtnEvent(' + rowdata.id + ')"><i class="sqBtnIco_4"></i>编辑</a>';
                            d += '<a class="sq-button-hasicon ' + l_hidden_3 + '" href="javascript:deleteBankInfoDB(' + rowdata.id + ',' + 3 + ')"><i class="sqBtnIco_7"></i>删除</a>';
                        }
                        return d;
                    }
                }
            ],
            usePager: false,
            root: 'rows',
            record: 'total',
            hideLoadButton: true,
            width: '100%',
            height: 200,
            heightDiff: -2,
            enabledEdit: false,
            isScroll: true,
            checkbox: false,
            rownumbers: true,
            allowUnSelectRow: true,
            alternatingRow: false,
            enabledSort:false
        });
    }

    function confirmStlBankInfo() {
        $.ajax({
            type: 'post',
            dataType: 'json',
            data: {
                paySchId: _paySchId,
                fundFlowCd: ProjectConstant.CODE_PAY_SCH_FUND_FLOW_CD_OUT,
                fundTypCd: ProjectConstant.CODE_PAY_SCH_FUND_TYP_CD_OUT,
            },
            url: basePath + '/settle/bank/confirmStlBankInfo.do',
            beforeSend: function () {
                wait_dialog = $.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING, SQ_type: "waitting"});
            },
            success: function (msg) {
                wait_dialog.close();
                if (msg.success == 1) {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "success"});
                } else {
                    $.ligerDialog.SQalert({content: msg.info, SQ_type: "error"});
                }
            }
        });
    }
</script>
